
const ChildComponent2 = (props) => {
    const sendMessage = () => {
        props.onSendMessage('Message from Child!');   // 调用父组件利用 props 传入的回调函数
    };

    return (
        <div>
            <h2>Child Component</h2>

            <button onClick={sendMessage}>Send Message</button>

        </div>

    );
};

export default ChildComponent2;